package com.atguigu.jxc.controller;

/**
 * @author wswdkl
 * @version 1.0
 * @date 2022/2/11 14:44
 */

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author wswdkl
 * @version 1.0
 * @date 2022/2/11 9:50
 */
@Controller
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 分页查询客户信息
     * @param page
     * @param rows
     * @param customerName
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public Map<String,Object> queryCustomerPage(Integer page, Integer rows, String customerName) {
        return customerService.queryCustomerPage(page,rows,customerName);
    }

    /**
     * 添加或者修改客户信息
     * @param customer
     * @return
     */
    @PostMapping("save")
    @ResponseBody
    public ServiceVO saveCustomer(Customer customer) {
        boolean flag = customerService.saveCustomer(customer);
        if(flag) {
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        } else {
            return new ServiceVO(-1,"请求失败");
        }
    }

    /**
     * 删除用户信息
     * @param ids
     * @return
     */
    @PostMapping("delete")
    @ResponseBody
    public ServiceVO deleteCustomer(String ids) {
        boolean flag = customerService.deleteCustomer(ids);
        if(flag) {
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        } else {
            return new ServiceVO(-1,"请求失败");
        }
    }

}
